<#include "/admin/_inc/_head.html"/>
<#include "/admin/_inc/_layout.html" />
<!DOCTYPE html>
<html lang="en">

<head>
    <@head />

    <link href="/assets/lib/zTree/v3/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .mfs-container {
            /* min-width: 150px;max-height: 100px;  */
            /* position: relative; */
        }

        .mfs-selected-option {
            border: 1px #ccc solid;
            display: inline-block;
            width: 100%;
            font-size: 14px;
            height: 31px;
            line-height: 2.42857;
            padding-left: 4px;
        }

        .mfs-options {
            position: absolute;
            border: 1px #ccc solid;
            /* border-top:0px; */
            width: 100%;
            margin: 0;
            padding: 0px;
            color: #333;
            overflow: auto;
            min-height: 100px;
            max-height: 300px;
            background: #ffffff;
            z-index: 9;
            margin-top: -6px;
        }
    </style>
</head>

<body>
<@layout>
<div class="pd-20">

    <form action="<#if model?exists>${ctx_admin}/role/update<#else>${ctx_admin}/role/add</#if>" method="post" class="form form-horizontal"
          id="form-add">

        <input id="roleId" type="hidden" value="${roleId}">
        <!--<div id="menuIdList">
        </div>
        <div class="row cl"  style="margin-top: 0;">
            <div class="col-10 col-offset-0">
                <button type="submit" class="btn btn-success radius" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
            </div>
        </div>-->
        <ul id="tree" class="ztree" style="margin-top: 0; width: 160px;"></ul>

    </form>


</div>
</@layout>

<@editjs />
<script type="text/javascript" src="/assets/lib/zTree/v3/js/jquery.ztree.all-3.5.js"></script>
<script type="text/javascript" src="/assets/js/droptree.js"></script>
<script type="text/javascript" >

    var zTree = null,treeNodes=null;
    var setting = {
        check: {
            enable: true,
            autoCheckTrigger: true
        },
        data: {
            key : {
                //name : "resourceName",
            },
            simpleData: {
                enable:true,
                //idKey: "resourceId",
                //pIdKey: "perentResourceId",
                //rootPId: ""
            }
        },
        view: {
            //expandSpeed: "slow",
            showIcon: true
        },
        callback:{
            onCheck:function (event, treeId, treeNode) {
                //alert(treeNode.tId + ", " + treeNode.name + "," + treeNode.checked);
                var data={};
                data.resourceId=treeNode.id;
                data.checked=treeNode.checked;
                $.ajax({
                    type: "POST",
                    data:data,
                    dataType: 'json',
                    url:global.adminPath+ '/role/auth/edit/'+$('#roleId').val(),
                    success: function(res){
                        if(res.success){

                        }else{
                            layer.msg(res.message, {icon: 1});
                        }
//                        layer.open({
//                            type: 1,
//                            title: false,
//                            closeBtn: 0, //不显示关闭按钮
//                            shade: [0],
//                            area: ['300px', '200px'],
//                            offset: 'rb', //右下角弹出
//                            time: 2000, //2秒后自动关闭
//                            anim: 2,
//                            content: res.message, //iframe的url，no代表不显示滚动条
//                            end: function(){ //此处用于演示
//
//                            }
//                        });
                        //console.log(res);
                    }
                });
            }
        }
    };


    $(function () {
        $.ajax({
            async : false,
            cache:false,
            type: 'POST',
            dataType : "json",
            url: global.adminPath+'/role/auth/'+$('#roleId').val(),//请求的action路径
            error: function () {//请求失败处理函数
                alert('请求失败');
            },
            success:function(res){ //请求成功后处理函数。
                treeNodes = res.data;   //把后台封装好的简单Json格式赋给treeNodes
            }
        });
        zTree =$("#tree");
        zTree = $.fn.zTree.init(zTree, setting, treeNodes);
        zTree.expandAll(true);
    });



</script>



</body>

</html>